package entity;

import java.io.Serializable;
import javax.persistence.*;
import valueObject.UserVO;

/**
 *
 * @author David
 */
@Entity
@Table(name = "application_user")
public class User implements Serializable, JPAEntity<UserVO> {
    @Id
    @Basic(optional = false)
    @Column(name = "username")
    private String username;
    @Basic(optional = false)
    @Column(name = "password")
    private String password;
    /*@JoinColumn(name = "roleidRole", referencedColumnName = "roleidRole")
    @ManyToOne(optional = false)*/

    @ManyToOne
    private Role role;

    public User() {
    }

    public User(String username) {
        this.username = username;
    }

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Role getRoleidRole() {
        return role;
    }

    public void setRoleidRole(Role role) {
        this.role = role;
    }

    @Override
    public UserVO toValueObject() {
        UserVO userVO = new UserVO();
        userVO.setUsername(username);
        userVO.setPassword(password);
        userVO.setRole(role.toValueObject());
        return userVO;
    }

}